<?php

/**
 * PlatsetModel.php 注释
 * 
 * @package 
 * @subpackage 
 * @author rendong01 rendong237@126.com
 * 
 * : tool.php 11 2011-11-16 13:34:24Z rendong237@gmail.com $
 */
class PlatsetModel{
	/**
	 * 数据库对象
	 *
	 * @var Mysql
	 */
	private $db;
	
	/**
	 * 构造方法
	 *
	 * @param Mysql $db
	 */
	public function __construct($db)
	{
		$this->db = $db;
	}
		
	public function set($name, $value)
	{
		$name = $this->db->quote($name);
		$value = $this->db->quote($value);
		$this->db->query("replace into platset(name, value) values('$name', '$value');");
	}
	
	public function get($name)
	{
		return $this->db->fetchOne("select value from platset where name='" . $this->db->quote($name) . "'");
	}
	
	public function getmulti($arr_names)
	{
		$str = "";
		$comma = "";
		foreach ($arr_names as $v){
			$str.=$comma . '"' . $this->db->quote($v) . '"';
			$comma = ',';
		}
		$ret = $this->db->fetchAssoc("select name, value from platset where name in($str)");
		
		$result = array();
		foreach ($arr_names as $v){
			if (!isset($ret[$v]))
				$result[$v] = "";
			else{
				$result[$v] = $ret[$v]['value'];
			}
		}
		
		return $result;
	}
}